package com.tansty.web.controller;

import com.tansty.common.utils.CommonUtil;
import com.tansty.pojo.dto.PermissionInputDTO;
import com.tansty.pojo.vo.ResultVO;
import com.tansty.service.service.PermissionService;
import com.tansty.service.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * description:  <br>
 * date: 2021/9/3 22:04 <br>
 * author: ztz <br>
 * version: 1.0 <br>
 */
@RestController
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    PermissionService permissionService;
    @Autowired
    UserService userService;
    @GetMapping("/all")
    public ResultVO getAllPerms(){
        return CommonUtil.ajaxReturn(permissionService.list());
    }
    @PreAuthorize("hasRole('ADMIN')")
    @PutMapping("/updateOne")
    public ResultVO updateOne(@RequestBody PermissionInputDTO permissionInputDTO){
       return CommonUtil.ajaxReturn( permissionService.updateOnePerm(permissionInputDTO));
    }
    @PreAuthorize("hasRole('ADMIN')")
    @DeleteMapping("/deleteOne/{id}")
    public ResultVO deleteOne(@PathVariable int id){
        return CommonUtil.ajaxReturn(userService.deletedOne(id));
    }

}
